home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Mine Kit.lua
< prev
next >
Wrap
Text File
|
2010-08-31
|
5KB
|
144 lines
--------------------------------------------------------------------------------
-- Weapon Mine Kit + Projectile Mine Kit
-- Original Carnage Contest Weapon
-- Script by DC, March 2010, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.minekit={}
cc.minekit.minekit={}
-- Load & Prepare Ressources
cc.minekit.gfx_icon=loadgfx("weapons/minekit.png") -- Weapon Icon
setmidhandle(cc.minekit.gfx_icon)
cc.minekit.gfx_wpn=loadgfx("weapons/mine.bmp") -- Weapon
setmidhandle(cc.minekit.gfx_wpn)
cc.minekit.sfx_attack=loadsfx("throw.ogg") -- Attack Sound
cc.minekit.sfx_bounce=loadsfx("bounce.wav") -- Bounce Sound
--------------------------------------------------------------------------------
-- Weapon: minekit
--------------------------------------------------------------------------------
cc.minekit.id=addweapon("cc.minekit","Mine Kit",cc.minekit.gfx_icon,0,2) -- Add Weapon (0 uses, first in round 2)
cc.minekit.ammo=3 -- 3 Mines
function cc.minekit.draw() -- Draw
if weapon_shots<cc.minekit.ammo then
if getplayeraction(0)==0 then
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
drawimage(cc.minekit.gfx_wpn,getplayerx(0)+getplayerdirection(0)*7,getplayery(0)+2)
end
-- HUD ammobar
if cc.minekit.ammo-weapon_shots>0 then
hudammobar(cc.minekit.ammo-weapon_shots,cc.minekit.ammo)
end
end
end
function cc.minekit.attack(attack) -- Attack
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
if (weapon_shots<cc.minekit.ammo) then
if attack==1 and weapon_timer<=0 then
-- No more weapon switching!
useweapon(0)
playsound(cc.minekit.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.minekit.minekit.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+getplayerdirection(0)*7
projectiles[id].y=getplayery(0)+2
-- Set speed of projectile
projectiles[id].sx=getplayerdirection(0)*0.5
projectiles[id].sy=-1
-- Timer
weapon_timer=50
-- End Turn
if weapon_shots>=cc.minekit.ammo then
endturn()
end
end
end
end
--------------------------------------------------------------------------------
-- Projectile: minekit
--------------------------------------------------------------------------------
cc.minekit.minekit.id=addprojectile("cc.minekit.minekit") -- Add Projectile
function cc.minekit.minekit.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
-- Draw projectile
drawimage(cc.minekit.gfx_wpn,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.minekit.minekit.update(id) -- Update
-- Gravity influence on speed + decrease x speed
projectiles[id].sx=projectiles[id].sx*0.95
projectiles[id].sy=projectiles[id].sy+getgravity()
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
-- Move X
projectiles[id].x=projectiles[id].x+msubx
if collision(cc.minekit.gfx_wpn,projectiles[id].x,projectiles[id].y)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if (math.abs(projectiles[id].sx)>0.5) then playsound(cc.minekit.sfx_bounce) end
projectiles[id].x=projectiles[id].x-msubx
projectiles[id].sx=-projectiles[id].sx*0.05
msubx=-msubx*0.05
end
else
projectiles[id].ignore=0
end
-- Move Y
projectiles[id].y=projectiles[id].y+msuby
if collision(cc.minekit.gfx_wpn,projectiles[id].x,projectiles[id].y)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if (math.abs(projectiles[id].sy)>0.5) then playsound(cc.minekit.sfx_bounce) end
projectiles[id].y=projectiles[id].y-msuby
projectiles[id].sy=-projectiles[id].sy*0.3
msuby=-msuby*0.3
-- Remove / Exchange with real minekit
if (math.abs(projectiles[id].sy)<0.3) then
createobject(o_mine,projectiles[id].x,projectiles[id].y)
freeprojectile(id)
end
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
playsound(sfx_hitwater1)
-- Free projectile
freeprojectile(id)
break
end
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end